|
1
|
|
|
/* |
|
2
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
|
3
|
|
|
* |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. See the COPYING file. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Maxence Lange <[email protected]> |
|
8
|
|
|
* @copyright 2018 |
|
9
|
|
|
* @license GNU AGPL version 3 or any later version |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
/** global: searchbar */ |
|
27
|
|
|
/** global: api */ |
|
28
|
|
|
|
|
29
|
|
|
var settings = { |
|
30
|
|
|
|
|
31
|
|
|
delay_provider: 300, |
|
32
|
|
|
delay_result: 150, |
|
33
|
|
|
|
|
34
|
|
|
searchRequestTimer: 4000, |
|
35
|
|
|
searchEntryTimer: 1500, |
|
36
|
|
|
parent: null, |
|
37
|
|
|
searchProviderId: '', |
|
38
|
|
|
searchProviderName: '', |
|
39
|
|
|
resultContainer: null, |
|
40
|
|
|
resultHeader: null, |
|
41
|
|
|
resultFooter: null, |
|
42
|
|
|
entryTemplate: null, |
|
43
|
|
|
entryTemplateDefault: null, |
|
44
|
|
|
// divNoResult: null, |
|
45
|
|
|
options: [], |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* generate the default template to display search result entries |
|
49
|
|
|
*/ |
|
50
|
|
|
generateDefaultTemplate: function () { |
|
51
|
|
|
|
|
52
|
|
|
var resultContent = $('<div>', {class: 'result_content'}); |
|
53
|
|
|
resultContent.append($('<div>', { |
|
54
|
|
|
id: 'title', |
|
55
|
|
|
class: 'result_title' |
|
56
|
|
|
})); |
|
57
|
|
|
resultContent.append($('<div>', { |
|
58
|
|
|
id: 'extract', |
|
59
|
|
|
class: 'result_extract' |
|
60
|
|
|
})); |
|
61
|
|
|
|
|
62
|
|
|
var resultEntry = $('<div>', {class: 'result_entry'}); |
|
63
|
|
|
resultEntry.append($('<div>', {class: 'result_div_checkbox'})); |
|
64
|
|
|
|
|
65
|
|
|
resultEntry.append($('<div>', {class: 'result_div result_div_content'}).append(resultContent)); |
|
66
|
|
|
|
|
67
|
|
|
var resultRight = $('<div>', {class: 'result_div result_div_right'}); |
|
68
|
|
|
resultRight.append($('<div>', {id: 'source'})); |
|
69
|
|
|
resultRight.append($('<div>', {id: 'info'})); |
|
70
|
|
|
resultEntry.append(resultRight); |
|
71
|
|
|
|
|
72
|
|
|
return $('<div>').append(resultEntry); |
|
73
|
|
|
}, |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
// var divLeft = $('<div>', {class: 'result_entry_left'}); |
|
78
|
|
|
// divLeft.append($('<div>', {id: 'title'})); |
|
79
|
|
|
// divLeft.append($('<div>', {id: 'line1'})); |
|
80
|
|
|
// divLeft.append($('<div>', {id: 'line2'})); |
|
81
|
|
|
// |
|
82
|
|
|
// var divRight = $('<div>', {class: 'result_entry_right'}); |
|
83
|
|
|
// //divRight.append($('<div>', {id: 'score'})); |
|
84
|
|
|
// |
|
85
|
|
|
// var div = $('<div>', {class: 'result_entry_default'}); |
|
86
|
|
|
// div.append(divLeft); |
|
87
|
|
|
// div.append(divRight); |
|
88
|
|
|
// |
|
89
|
|
|
// return $('<div>').append(div); |
|
90
|
|
|
// }, |
|
91
|
|
|
|
|
92
|
|
|
// |
|
93
|
|
|
// /** |
|
94
|
|
|
// * generate a no result display |
|
95
|
|
|
// */ |
|
96
|
|
|
// generateNoResultDiv: function () { |
|
97
|
|
|
// var div = $('<div>', {id: 'noresult'}); |
|
98
|
|
|
// div.html('no result'); |
|
99
|
|
|
// div.hide(); |
|
100
|
|
|
// settings.divNoResult = div; |
|
101
|
|
|
// }, |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param template |
|
106
|
|
|
*/ |
|
107
|
|
|
setResultHeader: function (template) { |
|
108
|
|
|
settings.resultHeader = template; |
|
109
|
|
|
}, |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param template |
|
113
|
|
|
*/ |
|
114
|
|
|
setResultFooter: function (template) { |
|
115
|
|
|
settings.resultFooter = template; |
|
116
|
|
|
}, |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* used to set the template to display search result entries |
|
121
|
|
|
* |
|
122
|
|
|
* @param template |
|
123
|
|
|
*/ |
|
124
|
|
|
setEntryTemplate: function (template) { |
|
125
|
|
|
settings.entryTemplate = template; |
|
126
|
|
|
}, |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* used to set the container for the search result entries |
|
131
|
|
|
* |
|
132
|
|
|
* @param container |
|
133
|
|
|
*/ |
|
134
|
|
|
setResultContainer: function (container) { |
|
135
|
|
|
settings.resultContainer = container; |
|
136
|
|
|
// settings.resultContainer.prepend(settings.divNoResult); |
|
137
|
|
|
}, |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* initialize the full text search and assign a providerId |
|
142
|
|
|
* |
|
143
|
|
|
* @param providerId |
|
144
|
|
|
* @param providerName |
|
145
|
|
|
* @param parent |
|
146
|
|
|
*/ |
|
147
|
|
|
initFullTextSearch: function (providerId, providerName, parent) { |
|
148
|
|
|
settings.searchProviderId = providerId; |
|
149
|
|
|
settings.searchProviderName = providerName; |
|
150
|
|
|
settings.parent = parent; |
|
151
|
|
|
searchbox.init(); |
|
|
|
|
|
|
152
|
|
|
}, |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* check that the app that call the lib contains a specific method |
|
157
|
|
|
* |
|
158
|
|
|
* @param method |
|
159
|
|
|
* @returns {boolean} |
|
160
|
|
|
*/ |
|
161
|
|
|
parentHasMethod: function (method) { |
|
162
|
|
|
if (settings.parent === null) { |
|
163
|
|
|
return false; |
|
164
|
|
|
} |
|
165
|
|
|
return (typeof eval('settings.parent. ' + method) === "function"); |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
}; |
|
168
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.